package com.hy.erp.inventory.service ;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IMaterialsUseDao;
import com.hy.erp.inventory.pojo.MaterialsUse;
import com.hy.erp.inventory.pojo.interfaces.IMaterialsUse;
import com.hy.erp.inventory.service.interfaces.IMaterialsUseService;

/**
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:18:40</li>
 * <li>类型名称：MaterialsUseService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "materialsUseService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class MaterialsUseService
								extends
								AbstractBusinessService < IMaterialsUse >
																			implements
																			IMaterialsUseService
{

	@ Override
	public boolean addMaterialsUse (
										IMaterialsUse materialsUse )
	{

		if ( null == materialsUse )
		{
			return true ;
		}

		else
		{
			System.out
						.println ( "ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh" ) ;

			IMaterialsUseDao materialsUseDao =
												( IMaterialsUseDao ) this
																			.getDao ( IMaterialsUse.class ) ;

			return materialsUseDao
									.persist ( materialsUse ) ;
		}

	}

	@ Override
	public boolean modifyMaterialsUse (
										IMaterialsUse materialsUse )
	{

		if ( ( null == materialsUse )
				|| ( null == materialsUse
											.getIdentifier ( ) )
				|| ( materialsUse
									.getIdentifier ( )
									.trim ( )
									.length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{

			IMaterialsUseDao materialsUseDao =
												( IMaterialsUseDao ) this
																			.getDao ( IMaterialsUse.class ) ;

			if ( null == materialsUse )
			{
				throw new ArchitectureFoundationException (
															"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}

			return ( materialsUseDao
									.merge ( materialsUse ) != null ) ;
		}

	}

	@ Override
	public Integer removeMaterialsUse (
										String [ ] materialsUseIds )
	{
		if ( ( null == materialsUseIds )
				|| ( materialsUseIds.length == 0 ) )
		{
			return new Integer (
									0 ) ;
		}
		else
		{

			IMaterialsUseDao materialsUseDao =
												( IMaterialsUseDao ) this
																			.getDao ( IMaterialsUse.class ) ;

			return materialsUseDao
									.remove ( materialsUseIds ) ;
		}
	}

	@ Override
	public String [ ] addMaterialsUse (
										Object [ ] materialsUse )
	{


		if ( null == materialsUse )
		{
			return null ;
		}

		else
		{
		
			IMaterialsUseDao materialsUseDao =
												( IMaterialsUseDao ) this
																			.getDao ( IMaterialsUse.class ) ;

			MaterialsUse[] materialsUses=new MaterialsUse[materialsUse.length];
						for(int i=0;i<materialsUse.length;i++)
						{
							MaterialsUse materialsUse2=( MaterialsUse ) materialsUse[i];
							materialsUses[i]=materialsUse2;
						}
						return materialsUseDao
						                .persist ( materialsUses ) ;

			
		}

	
	}

	@ Override
	public List < IMaterialsUse > getAllMaterialsUse ( )
	{
		IMaterialsUseDao materialsUseDao =
			( IMaterialsUseDao ) this
										.getDao ( IMaterialsUse.class ) ;

return materialsUseDao
.find ( ) ;
	}

	@ Override
	public String [ ] modifyMaterialsUse (
											Object [ ] materialsUse )
	{



		if ( null == materialsUse )
		{
			return null ;
		}

		else
		{
		
			IMaterialsUseDao materialsUseDao =
												( IMaterialsUseDao ) this
																			.getDao ( IMaterialsUse.class ) ;

			MaterialsUse[] materialsUses=new MaterialsUse[materialsUse.length];
						for(int i=0;i<materialsUse.length;i++)
						{
							MaterialsUse materialsUse2=( MaterialsUse ) materialsUse[i];
							materialsUses[i]=materialsUse2;
						}
						return materialsUseDao
						                .merge  ( materialsUses ) ;

			
		}

	
	
	}

}
